import { _decorator, Component, instantiate, Node, Prefab, Vec3 } from 'cc';
import { ITEMTYPE, NUMBER } from './GameConstant';
import { ResourceUtil } from '../AshFramework/Utils/ResourceUtil';
import { PrefsManager } from './PrefsManager';
import { BundleManager, Bundles } from '../AshFramework/Managers/BundleManager';
const { ccclass } = _decorator;

@ccclass('ShowPanel')
export class ShowPanel extends Component {

    public static Instance: ShowPanel = null;

    protected onLoad(): void {
        ShowPanel.Instance = this;
    }

    show(itemType: ITEMTYPE, itemNumber: NUMBER) {
        this.node.removeAllChildren();
        let path: string = "Show/";
        if (ITEMTYPE.PF == itemType) {
            path += "ShowWeapon" + (Number(PrefsManager.Instance.userData.CurWeapon) + 1);
            BundleManager.LoadPrefab(Bundles.Prefabs, path).then((prefab: Prefab) => {
                const showNode: Node = instantiate(prefab);
                showNode.parent = this.node;
                showNode.setPosition(Vec3.ZERO);
            })
        } else if (ITEMTYPE.GC == itemType) {

        } else if (ITEMTYPE.GS == itemType && itemNumber != NUMBER.NUMBER1) {
            path += "ShowGS" + itemNumber;
            BundleManager.LoadPrefab(Bundles.Prefabs, path).then((prefab: Prefab) => {
                const showNode: Node = instantiate(prefab);
                showNode.parent = this.node;
            })
        }
    }

    showWeapon(number: NUMBER) {
        this.node.removeAllChildren();
        let path: string = "Show/ShowWeapon" + (Number(number) + 1);
        BundleManager.LoadPrefab(Bundles.Prefabs, path).then((prefab: Prefab) => {
            const showNode: Node = instantiate(prefab);
            showNode.parent = this.node;
            showNode.setPosition(Vec3.ZERO);
        })
    }
}


